﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.OleDb;
using DTO;
using DAO;
namespace BUS
{
    public class SanPhamBUS
    {
        public int ThemSanPham(SanPhamDTO spDTO)
        {
            SanPhamDAO dao = new SanPhamDAO();
            int kq = dao.ThemSanPham(spDTO);
            return kq;
        }
        public List<SanPhamDTO>LayDSSP()
        {
            SanPhamDAO sp = new SanPhamDAO();
            return sp.LayDSSanPham();
        }
        public List<SanPhamDTO> SanPhamNotInCTHoaDon(int hd)
        {
            SanPhamDAO sp = new SanPhamDAO();
            return sp.SanPhamNotInCTHoaDon(hd);
        }
        public int XoaSanPham(int MaSP)
        {
            SanPhamDAO dao = new SanPhamDAO();
            return dao.XoaSanPham(MaSP);
        }
        public List<SanPhamDTO> ChiTietSP(int masp)
        {
            SanPhamDAO sp = new SanPhamDAO();
            return sp.ChiTietSanPham(masp);
        }
        public SanPhamDTO LayTTSP(int masp)
        {
            SanPhamDAO sp = new SanPhamDAO();
            return sp.LayTTSP(masp);
        }
        public int UpdateSP(SanPhamDTO sp)
        {
            SanPhamDAO dao = new SanPhamDAO();
            return dao.CapNhatSanPham(sp);
        }
        public int UpdateSLSP(int MaSP,int sl)
        {
            DAO.SanPhamDAO sp = new SanPhamDAO();
            return sp.CapNhatSLSanPham(MaSP, sl);
        }

        public List<SanPhamDTO> TimSanPham(string tensp)
        {
            SanPhamDAO sp = new SanPhamDAO();
            return sp.TimSanPham(tensp);
        }
        public static OleDbDataAdapter BCNXT(DateTime bd,DateTime kt)
        {
            DAO.SanPhamDAO ct = new DAO.SanPhamDAO();
            return ct.LayBaoCaoNhapXuatTon(bd,kt);
        }
        public int SoDuDK(int MaSP,DateTime dt)
        {
            DAO.SanPhamDAO sp = new DAO.SanPhamDAO();
            return (int)sp.SoDuDK(MaSP, dt);
        }

        public string LayTenSP(int maSP)
        {
            SanPhamDAO dao = new SanPhamDAO();
            return dao.LayTenSP(maSP);

        }

        public int KiemTraThuoc(int maSP)
        {
            SanPhamDAO sp = new SanPhamDAO();
            List<SanPhamDTO> danhsach = sp.LayDSSanPham();
            for (int i = 0; i < danhsach.Count; i++)
                if (danhsach[i].MaSP == maSP)
                    return 1;
            return 0;
        }
        
        public int TongNhap(int MaSP, DateTime bd, DateTime kt)
        {
            DAO.SanPhamDAO sp = new DAO.SanPhamDAO();
            return (int)sp.TongNhap(MaSP, bd, kt);
        }
        public int TongXuat(int MaSP, DateTime bd, DateTime kt)
        {
            DAO.SanPhamDAO sp = new DAO.SanPhamDAO();
            return (int)sp.TongXuat(MaSP, bd, kt);
        }
    }
}
